﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hired
{
    public partial class search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void rblCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (rblCategory.SelectedIndex)
            {
                case 0: // jobs
                    pnlJobs.Visible = true;
                    pnlPeople.Visible = false;
                    pnlCompanies.Visible = false;
                    pnlCourses.Visible = false;
                    break;
                case 1:// people
                    pnlJobs.Visible = false;
                    pnlPeople.Visible = true;
                    pnlCompanies.Visible = false;
                    pnlCourses.Visible = false;
                    break;
                case 2:// companies
                    pnlJobs.Visible = false;
                    pnlPeople.Visible = false;
                    pnlCompanies.Visible = true;
                    pnlCourses.Visible = false;
                    break;
                case 3:// courses
                    pnlJobs.Visible = false;
                    pnlPeople.Visible = false;
                    pnlCompanies.Visible = false;
                    pnlCourses.Visible = true;
                    break;
            }
        }

        protected void btnAdvSearch_Click(object sender, EventArgs e)
        {
            if (txtKeyword.Text != "" 
                || txtCompanyEmail.Text!="" 
                || txtExclude.Text!="" 
                || txtSalaryLowerLimit.Text!="" 
                || txtSalaryUpperLimit.Text!="" || txtSchool.Text!=""
                || ddlCourseIndustry.SelectedIndex!=0 
                || ddlCourseLocation.SelectedIndex!=0
                || ddlJobIndustry.SelectedIndex!=0
                || ddlLocation.SelectedIndex!=0
                )
            {
                string appendQuery = "";
                if (rblCategory.SelectedIndex == 0)
                {
                    appendQuery = "&jobLocation=" + Server.UrlEncode(ddlLocation.SelectedValue) +
                        "&jobIndustry=" + Server.UrlEncode(ddlJobIndustry.SelectedValue) +
                        "&salaryLowerLimit=" + Server.UrlEncode(txtSalaryLowerLimit.Text) +
                        "&salaryUpperLimit=" + Server.UrlEncode(txtSalaryUpperLimit.Text);
                }
                if (rblCategory.SelectedIndex == 1)
                {
                    appendQuery = "&educationalInstitute=" + Server.UrlEncode(txtSchool.Text);
                }
                if (rblCategory.SelectedIndex == 2)
                {
                    appendQuery = "&companyEmail=" + Server.UrlEncode(txtCompanyEmail.Text);
                }
                if (rblCategory.SelectedIndex == 3)
                {
                    appendQuery = "&relevantIndustry=" + Server.UrlEncode(ddlCourseIndustry.SelectedValue) +
                        "&courseLocation=" + Server.UrlEncode(ddlCourseLocation.SelectedValue);
                }
                Response.Redirect("results.aspx?fromAdvancedSearch=true" +
                    "&category=" + Server.UrlEncode(rblCategory.SelectedValue) +
                    "&keywords=" + Server.UrlEncode(txtKeyword.Text) +
                    "&exclude=" + Server.UrlEncode(txtExclude.Text) +
                    appendQuery);
            }
            else {
                lblAdvSearchError.Visible = true;
            }
        }
    }
}